package myjava.h_exception;

import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;

/**
 * @Auther: cty
 * @Date: 2019/11/8 下午8:48
 * @Description: myjava.h_exception  测试Checked Exception  编译时处理的异常
 * @version: 1.0
 */
public class B_Checked {
    public static void main(String[] args) {
        FileReader reader = null;

        try {
            reader = new FileReader("666.txt");
            char c1 = (char)reader.read();  //默认读出时int型，需强制转换为char型
            System.out.println(c1);
        } catch (FileNotFoundException e) {  //FileNotFoundException是IOException的子类，要放在前面，否则永远不会运行
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                if(reader!=null){  //文件只有成功打开了才关闭
                    reader.close();
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}
